package dm.ass2.eval.io;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;

public class ErrorWritable implements Writable{
    private int size;
	private int[] num;
    private double[] error;
	 
    public ErrorWritable(){
    	
    }
    public ErrorWritable(int size,int num[] , double error[]){
    	super();
    	this.size = size;
    	this.num = num;
    	this.error = error;  	
    }
    public int[] getNum(){
    	return this.num;
    }
    public double[] getError(){
        return this.error;	
    } 
    public int getSize(){
    	return this.size;
    }
	@Override
	public void readFields(DataInput in) throws IOException {
		int numOfNums = in.readInt();
		this.size = numOfNums;
		this.num = new int[numOfNums];
		for (int i = 0; i < numOfNums; i++) {
			this.num[i] = in.readInt();
		}
		this.error = new double[numOfNums];
		for (int i = 0; i < numOfNums; i++) {
			this.error[i] = in.readDouble();
		}
	}
	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(this.size);
		for (int i = 0; i < this.size; i++) {
			out.writeInt(this.num[i]);
		}
		for (int i = 0; i < this.size; i++){
			out.writeDouble(this.error[i]);
		}
	}
	

}
